package com.firewolf.cloud.controller;

import com.test.entities.User;
import com.test.service.UserService;
import com.test.entities.User;
import com.test.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping
public class TestController {

    @Autowired
    private UserService userService;

    @PostMapping
    public String add(User u) {
        return  userService.add(u);
    }

    @PostMapping("add")
    public String add(String name,Integer age) {
        return  userService.add(name,age);
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Integer uid) {
        return userService.delete(uid);
    }

    @PutMapping
    public String update(User u) {
        return userService.update(u);
    }


    @GetMapping
    public List<User> list(@RequestParam("name") String name,@RequestParam("age")  Integer age) {
        return userService.list(name,age);
    }

    @GetMapping("list")
    public List<User> list(User u) {
        return userService.list2(u);
    }
}
